﻿using System;

namespace oueb.core
{
    public class CorsBuilder
    {
        public bool Credentials { get; private set; }
        public string Headers { get; private set; }
        public string Methods { get; private set; }
        public string Origin { get; private set; }

        public CorsBuilder AllowAnyHeaders()
        {
            this.Headers = "*";
            return this;
        }
        public CorsBuilder AllowAnyMethod()
        {
            this.Methods = "*";
            return this;
        }
        public CorsBuilder AllowAnyOrigin()
        {
            this.Origin = "*";
            return this;
        }
        public CorsBuilder AllowCredentials()
        {
            this.Credentials = true;
            return this;
        }
        public CorsBuilder WithHeaders(params string[] values)
        {
            this.Headers = string.Join(",", values);
            return this;
        }
        public CorsBuilder WithMethods(params string[] values)
        {
            this.Methods = string.Join(",", values);
            return this;
        }
        public CorsBuilder WithOrigin(string value)
        {
            this.Origin = value;
            return this;
        }
        public CorsPolicy Build()
        {
            return new CorsPolicy(this.Credentials, this.Headers, this.Methods, this.Origin);
        }
    }
}
